﻿using MediatR;
using T_vehicle.API.Application.Command.ExpensesCommand;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.ExpensesCommandHandlers
{
    public class PDelExpensesCommandHandlers:IRequestHandler<PDelExpensesCommand,int>
    {
        private readonly IExpensesRepository expensesRepository;

        public PDelExpensesCommandHandlers(IExpensesRepository expensesRepository)
        {
            this.expensesRepository = expensesRepository;
        }

        public async Task<int> Handle(PDelExpensesCommand request, CancellationToken cancellationToken)
        {
            var Id = request.ExpensesId.Split(',').Select(x => Convert.ToInt32(x));
            var list = await expensesRepository.GetAsync(x => Id.Contains(x.ExpensesId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await expensesRepository.UpdateAsyncRange(list);
        }
    }
}
